﻿using HR.Filters;
using HR.IService;
using HR.Models;
using Microsoft.AspNetCore.Mvc;

namespace HR.Controllers
{
    public class EngageInterviewController : Controller
    {

        //简历登记服务接口,用于面试时筛选的简历
        private readonly IEngageResumeService iers;
        //面试表服务的接口
        private readonly IEngageInterviewService ieis;

        public EngageInterviewController(IEngageResumeService iers, IEngageInterviewService ieis)
        {
            this.iers = iers;
            this.ieis = ieis;
        }
        [TypeFilter(typeof(RoleFilterAttribute))]
        public IActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 筛选有效简历进行面试
        /// </summary>
        /// <param name="erf"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> ERFiltrate2([FromBody] EngageResumeFiltrate erf)
        {
            List<engage_resume> list = await iers.ERFiltrate2(erf);
            return Json(list);
        }
        /// <summary>
        /// 面试记录根据简历编号来回显最近一次面试，包括面试次数
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> EngageInterviewRecord(short res_id)
        {
            engage_interview ei = await ieis.EngageInterviewRecord(res_id);
            //ViewBag.interviewAmount = ei.interview_amount.ToString();
            //string ck = ViewBag.interviewAmount;
            return Json(ei);
        }
        /// <summary>
        /// 新增面试信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> EngageInterviewAdd([FromBody] engage_interview ei)
        {
            ei.register = HttpContext.Session.GetString("uname");
            int res = await ieis.EngageInterviewAdd(ei);
            return Json(res);
        }
    }
}
